{{ ansible_managed | comment }}
# Documentation: http://docs.grafana.org/installation/ldap/
{% if 'verbose_logging' in grafana_ldap %}
verbose_logging = {{ 'true' if grafana_ldap.verbose_logging else 'false' }}
{% endif %}

[[servers]]
{% for k,v in grafana_ldap.servers.items() if k != 'attributes' %}
{%   if k == 'port' %}
{{ k }} = {{ v | int }}
{%   elif v in [True, False] %}
{{ k }} = {{ 'true' if v else 'false' }}
{%   else %}
{{ k }} = {{ v | to_nice_json }}
{%   endif %}
{% endfor %}

[servers.attributes]
{% for k,v in grafana_ldap.servers.attributes.items() %}
{{ k }} = {{ v | to_nice_json }}
{% endfor %}

{% for org in grafana_ldap.group_mappings %}
{%   if 'name' in org %}
# {{ org.name }}
{%   endif %}
{%   for group in org.groups %}
[[servers.group_mappings]]
org_id = {{ org.id }}
{%     for k,v in group.items() %}
{%   if v in [True, False] %}
{{ k }} = {{ 'true' if v else 'false' }}
{%   else %}
{{ k }} = "{{ v }}"
{%   endif %}
{%     endfor %}

{%   endfor %}
{% endfor %}
